type CartItem = {
  item: string;
  price: string;
  quantity?: number;
};

type User = {
  firstName: string;
  lastName: string;
  age: number;
  cartItem: CartItem;
};

const user: User = {
  firstName: "John",
  lastName: "Doe",
  age: 30,
  cartItem: {
    item: "Apple",
    price: "1.99",
    quantity: 5,
  },
};

// 解构 firstName
const { firstName } = user;
console.log(firstName);

const secondUser: User = {
  firstName: "Second",
  lastName: "User",
  age: 10,
  cartItem: {
    item: "Banana",
    price: "2.99",
    quantity: 10,
  },
};

// 给解构出来的命名 secondName
const { firstName: secondName } = secondUser;
console.log(secondName);

const {
  cartItem: { price, item },
  ...getAnythin
} = user;
// 展开运算符 ...这里就是将剩余的属性全部放到 getAnythin这个对象里
console.log(getAnythin);

console.log(price, item);

function printCartItem({ cartItem }: User): void {
  console.log(cartItem);
  printCartItem(user);
}
